<?php

/**

 * 我的工作流程
 * 
 * @access  public 
 * @author  zhangyingheng<zhang_yh@jsumt.com.cn> 
 */

namespace Index\Controller;

use Think\Controller;

class FlowController extends BaseController {

    public function _initialize() {
        parent::_initialize();
    }

    public function index() {

        $this->display();
    }

    

    public function pageNum($flag) {
        //分页
        $flag = rtrim(implode(',', $flag), ',');
        $sql = "select count(*) from flow_run_prcs as a left join flow_run as b on a.RUN_ID = b.RUN_ID where a.USER_ID ='" . session('user_id');
        $sql .= "' and a.PRCS_FLAG in (" . $flag . ") and b.DEL_FLAG = 0 order by a.RUN_ID DESC";

        $num = M()->query($sql);
        return $num[0]['count(*)'];
    }

    public function lists() {
        $flag = [1, 2];
        $limit = $this->limit;
        //$limit = 2;
        $runs = $this->getLists($flag, $limit, 1);
        //print_r($runs);
        $num = $this->pageNum($flag);
        $this->pages = $this->pageLists($num, $limit);
        getChineseName();
        //$runs[0]['begin_user'] = getChineseName($runs[0]['begin_user']);
        $this->runs = $runs;
        $this->display();
    }

    public function overLists() {
        $flag = [3, 4];
        $limit = $this->limit;
        //$limit = 2;
        $runs = $this->getLists($flag, $limit, 2);
        $this->runs = $runs;
        $num = $this->pageNum($flag);
        $this->pages = $this->pageLists($num, $limit);
        $this->display();
    }

    public function droploadNot() {
        $flag = [1, 2];
        $limit = $this->limit;
        //$limit = 2;
        $runs = $this->getLists($flag, $limit, 1);
        //print_r($runs);die;
        foreach ($runs as $key => $row) {
            $runs[$key]['begin_user'] = getChineseName($row['begin_user']);
            $runs[$key]['user'] = getChineseName($row['user']);
        }
        $this->ajaxReturn($runs);
    }
    
    public function droploadFinish(){
        $flag = [3,4];
        $limit = $this->limit;
        //$limit = 2;
        $runs = $this->getLists($flag, $limit, 2);
        //print_r($runs);die;
        foreach ($runs as $key => $row) {
            $runs[$key]['begin_user'] = getChineseName($row['begin_user']);
            $runs[$key]['user'] = getChineseName($row['user']);
        }
        $this->ajaxReturn($runs);
    }

    //删除我的流程
    public function delFlow() {
        $run_id = I('run_id');
        $res1 = M('flow_run_prcs')->where('RUN_ID=' . $run_id)->delete();
        $res2 = M('flow_run')->where('RUN_ID=' . $run_id)->delete();
        $res3 = M('flow_run_data')->where('RUN_ID=' . $run_id)->delete();
        $res4 = M('flow_run_log')->where('RUN_ID=' . $run_id)->delete();
        if ($res1 !== false && $res2 !== false && $res3 !== false && $res4 !== false) {
            $return['info'] = '删除成功';
        } else {
            $return['info'] = '删除失败';
        }
        $this->ajaxReturn($return);
    }

}
